import router from "@/router"
import AxiosMethods from "@/util/AxiosMethods"
const state = {
    project: {
        createruid:null,
        pid:'',
        title:'',
        // 图片的名称
        imageName:'10001.png',
        description:'',// 项目简介
        content:'',// 项目内容
        target:0,// 目标金额
    }
}
const mutations = {
    updateProjectInfo(state, project){
        state.project.createruid=project.uid
        state.project.title=project.name
        state.project.description=project.desc
        state.project.target=project.target
        // console.log(state.project)
    },
    updateProjectImage(state, imageName){
        state.project.imageName = imageName
        // console.log(state.project.imageName)
    },
    updateProjectContent(state, content) {
        state.project.content = content;
        // console.log(state.project.content)
    }
}
const actions = {
    async createProject({commit, state}){
        const parms = {
            name: state.project.title,// 项目名称
            synopsis: state.project.description,// 项目简介
            create: state.project.createruid,// 创建者的uid
            target: state.project.target,// 目标金额
            content: state.project.content,// 项目内容
            photo: state.project.imageName// 项目图片名称
        }
        try{
            const res = await AxiosMethods.post('/project/add', parms)
            // console.log("提交成功",res)
            router.push('/project')
        }catch(err){
            console.log(err)
        }
    },
}
const getters = {}

export default {
    namespaced: true,
  state,
  mutations,
  actions,
  getters
}